package com.sgb.kjwl.view.ui.activity.vehicleManagement;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;

import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.GridLayoutManager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.alimaplibrary.util.ToastUtil;
import com.sgb.capital.view.widget.MToast;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityVehicleDetailsBinding;
import com.sgb.kjwl.di.vehicleManagement.DaggerVehicleDetailComponent;
import com.sgb.kjwl.di.vehicleManagement.VehicleDetailModule;
import com.sgb.kjwl.model.entity.CompanyDetailsEntity;
import com.sgb.kjwl.model.entity.transport.QueryTwoCarrierVO;
import com.sgb.kjwl.model.entity.transport.VehicleDetail;
import com.sgb.kjwl.model.entity.transport.Way;
import com.sgb.kjwl.utils.NumberUtil;
import com.sgb.kjwl.utils.VehicleConstant;
import com.sgb.kjwl.view.ui.activity.manage.WebsiteInfoActivity;
import com.sgb.kjwl.view.ui.activity.self.logistics.InquiryActivity;
import com.sgb.kjwl.view.ui.activity.self.userInfo.VerificationCodeLoginActivity;
import com.sgb.kjwl.view.ui.activity.transport.InquireByLetterActvity;
import com.sgb.kjwl.view.ui.activity.transport.MoreCarriageInfoActivity;
import com.sgb.kjwl.view.ui.activity.transport.ShareLogisticsActivity;
import com.sgb.kjwl.view.ui.adapter.transport.OftenDeliverCityAdapter;
import com.sgb.kjwl.view.widget.ItemDeliverView;
import com.sgb.kjwl.viewmodel.transport.VehicleDetailModel;
import com.sgb.member.MemberConfig;
import com.sgb.member.entity.QualityMemberBean;
import com.sgb.member.ui.activity.ComApplyOrInvitePersonActivity;
import com.sgb.member.ui.activity.ComApplyOrInvitePersonShenPiActivity;
import com.sgb.member.weight.MemberCommonDialog;
import com.swgk.core.base.aroute.AppRouteConstant;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.dialog.RoundDialog;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.PermissionCheckUtil;
import com.swgk.core.util.SharedPreferenceUtil;
import com.swgk.core.util.StringUtil;
import com.swgk.core.util.UserOperating;

import java.util.Iterator;

import javax.inject.Inject;

/**
 * 车辆详情
 */
@Route(path = AppRouteConstant.WuLui.ROUTER_PATH_VEHICLEDETAILACTIVITY)
public class VehicleDetailActivity extends AppActivity {
    ActivityVehicleDetailsBinding binding;
    @Inject
    VehicleDetailModel model;
    String driverAuthNo;

    private VehicleDetail vehicleDetail;

    public static void start(Context context, String driverAuthNo) {
        Intent intent = new Intent();
        intent.setClass(context, VehicleDetailActivity.class);
        intent.putExtra("driverAuthNo", driverAuthNo);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);//清空并复用之前的
        context.startActivity(intent);
    }

    public static void startNew(Context context, String driverAuthNo) {
        Intent intent = new Intent();
        intent.setClass(context, VehicleDetailActivity.class);
        intent.putExtra("driverAuthNo", driverAuthNo);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);//清空并新建
        context.startActivity(intent);
    }


    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerVehicleDetailComponent.builder()
                .appComponent(appComponent)
                .vehicleDetailModule(new VehicleDetailModule(this))
                .build()
                .inject(this);
    }


    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_vehicle_details);
        driverAuthNo = getIntent().getExtras().getString("driverAuthNo");
        binding.ivBack.setOnClickListener(v -> finish());
        model.loadData(this, driverAuthNo);
        model.ldInquiry.observe(this, new Observer<Boolean>() {
            @Override
            public void onChanged(Boolean aBoolean) {
                if (aBoolean) {
                    if (vehicleDetail != null)
                        InquiryActivity.startCarInquiry(VehicleDetailActivity.this, String.valueOf(vehicleDetail.getDriverAuthNo()), vehicleDetail.getTelphone());
                } else {
                    MToast.showToast(VehicleDetailActivity.this, "不能对自己发布的车辆进行询价！");
                }
            }
        });

        model.statusLiveData.observe(this, status -> {
            if (status.equals("1")) {
                MemberCommonDialog dialog = new MemberCommonDialog(new MemberCommonDialog.SimpleListener() {
                    @Override
                    public void onPositive(Object... objects) {
                        // 跳转填写审批信息// 审批类型 1 申请加盟(固定传1就行) 2邀请加盟
                        jumpJoinPage(status);
                    }
                }, MemberCommonDialog.STYLE_INVITE_JOIN);
                dialog.show(getActivity(), "MemberCommonDialog");
            } else {
                jumpJoinPage(status);
            }
        });
    }

    private void jumpJoinPage(String status) {
        // 跳转邀请加盟申请页
        if (status.equals("1")) {//有审批
            ComApplyOrInvitePersonShenPiActivity.start(this, bean1, false, 0);//0 表示邀请  企业  邀请  个人
        } else {//无审批
            ComApplyOrInvitePersonActivity.start(this, bean1, false, 0); //    企业  邀请  个人
        }
    }

    QualityMemberBean bean;

    private QualityMemberBean getQualityMemberBean(CompanyDetailsEntity companyDetailsEntity) {
        if (null == bean) {
            bean = new QualityMemberBean();
            bean.setCompanyNo(companyDetailsEntity.getCompanyNo());
            bean.setCompanyName(companyDetailsEntity.getCompanyName());
            bean.setServiceTypeName(companyDetailsEntity.getServiceTypeName());
            bean.setServiceType(companyDetailsEntity.getServiceType());
            bean.setCompanyId(companyDetailsEntity.getId());
            bean.setProvinceNo(companyDetailsEntity.getProvinceNo());
            bean.setCityNo(companyDetailsEntity.getCityNo());
            bean.setDistrictNo(companyDetailsEntity.getDistrictNo());
            bean.setAddress(companyDetailsEntity.getMapAddress());
            bean.setApproveType("2");//邀请
        }
        return bean;
    }

    public void refreshData(VehicleDetail vehicleDetail) {
        try {
            if (vehicleDetail == null) {
                return;
            }

            binding.contentLayout.setVisibility(View.VISIBLE);
            binding.bidLayout.setVisibility(View.VISIBLE);
            binding.enquiry.setVisibility(View.VISIBLE);
            this.vehicleDetail = vehicleDetail;

            RequestOptions optionsCompany = new RequestOptions()
                    .placeholder(R.drawable.vehicle_detail_paceholder)//图片加载出来前，显示的图片
                    .fallback(R.drawable.vehicle_detail_paceholder) //url为空的时候,显示的图片
                    .error(R.drawable.vehicle_detail_paceholder);//图片加载失败后，显示的图片
            if (!isDestroyed()) {
                Glide.with(this).load(vehicleDetail.getCarImage()).apply(optionsCompany).into(binding.vehicleImg);
            }

            binding.vehicleNumber.setText(vehicleDetail.getCarNumber());
            binding.vehicleNumberTwo.setText(vehicleDetail.getCarNumber());
            binding.vehicleLength.setText(vehicleDetail.getCarLenName());
            if (vehicleDetail.getUpdateTime() != null) {
                binding.updateTime.setText(DateUtils.stampToDay(String.valueOf(vehicleDetail.getUpdateTime())));
            }


            //设置车辆颜色
            binding.vehicleColor.setText(TextUtils.isEmpty(vehicleDetail.getLicensePlateColor()) ? "/" : vehicleDetail.getLicensePlateColor());

            //设置载重
            binding.vehicleWeight.setText(VehicleConstant.getTrim0Str(vehicleDetail.getWeight()) + "吨");

            //设置车型
            if (!TextUtils.isEmpty(vehicleDetail.getCarTypeName())) {
                binding.vehicleShape.setText(vehicleDetail.getCarTypeName());
            } else {
                binding.carTypeLayout.setVisibility(View.GONE);
            }

            //设置车长
            if (!TextUtils.isEmpty(vehicleDetail.getCarLenName())) {
                binding.vehicleLength.setText(vehicleDetail.getCarLenName());
            } else {
                binding.vehicleLength.setText("/");
            }

            //司机地址
            if (!TextUtils.isEmpty(vehicleDetail.getDetailAddress())) {
                binding.driverAddress.setText(vehicleDetail.getDetailAddress());
                binding.addressLayout.setVisibility(View.VISIBLE);
            } else {
                binding.addressLayout.setVisibility(View.GONE);
            }

            StringBuilder otherFunction = new StringBuilder();

            //设置是否自卸
            if (vehicleDetail.getIsDumper() != null) {
                otherFunction.append(vehicleDetail.getIsDumper() == 0 ? "非自卸 " : "自卸 ");
            }

            //设置栏高
            if (!TextUtils.isEmpty(vehicleDetail.getHeightHurdle())) {
                otherFunction.append("栏高" + vehicleDetail.getHeightHurdle() + "米");
            }

            //设置其他功能
            if (!TextUtils.isEmpty(vehicleDetail.getFunctionNos())) {
                otherFunction.append(vehicleDetail.getFunctionNos());
            }
            if (!TextUtils.isEmpty(otherFunction)) {
                binding.vehicleFunction.setText(otherFunction.toString());
            } else {
                binding.vehicleFunctionLayout.setVisibility(View.GONE);
            }
            if (TextUtils.isEmpty(vehicleDetail.getTelphone())) {
                binding.connectPersonPhone.setText("/");
                binding.callPhone.setVisibility(View.GONE);
            } else {
                binding.connectPersonPhone.setText(StringUtil.gonePhone(vehicleDetail.getTelphone()));
                binding.callPhone.setVisibility(View.GONE);
            }
            binding.connectPersonName.setText(vehicleDetail.getName());
            setImIconVisibilityAndClickListener();
            binding.callPhone.setOnClickListener(this);
            binding.callPhoneCompany.setOnClickListener(this);
            binding.tvContactService.setOnClickListener(this);
            binding.moreDeliverInfo.setOnClickListener(this);
            binding.enquiry.setOnClickListener(this);
            binding.report.setOnClickListener(this);
            binding.inquiry.setOnClickListener(this);
            binding.tvCurrentLocation.setOnClickListener(this);
            binding.tvInvitation.setOnClickListener(this);
            binding.llLocationLayout.setOnClickListener(this);
            binding.llShareLayout.setOnClickListener(this);
            binding.tvMapOperation.setOnClickListener(this);
            setOftenCity();
            setCarrierVO();
            setDriverInfo();
        } catch (Exception e) {
            binding.contentLayout.setVisibility(View.GONE);
        }
    }

    private void setDriverInfo() {
        RequestOptions optionsperson = new RequestOptions()
                .placeholder(R.drawable.geren_person_touxiang)//图片加载出来前，显示的图片
                .fallback(R.drawable.geren_person_touxiang) //url为空的时候,显示的图片
                .error(R.drawable.geren_person_touxiang);//图片加载失败后，显示的图片
        RequestOptions optionsTeam = new RequestOptions()
                .placeholder(R.mipmap.icon_team_default_1)//图片加载出来前，显示的图片
                .fallback(R.mipmap.icon_team_default_1) //url为空的时候,显示的图片
                .error(R.mipmap.icon_team_default_1);//图片加载失败后，显示的图片
        RequestOptions optionsCompany = new RequestOptions()
                .placeholder(R.mipmap.icon_company_default)//图片加载出来前，显示的图片
                .fallback(R.mipmap.icon_company_default) //url为空的时候,显示的图片
                .error(R.mipmap.icon_company_default);//图片加载失败后，显示的图片
        if (!isDestroyed()) {
            if (vehicleDetail != null) {
                if (vehicleDetail.getTerminal() == 1) {
                    binding.clCompanyCarOwner.setVisibility(View.VISIBLE);
                    binding.clDriverLayout.setVisibility(View.GONE);
                    binding.llInfo.setVisibility(View.GONE);
                    binding.tvInfoTip.setText("隶属单位");
                    binding.phone.setText(TextUtils.isEmpty(vehicleDetail.getTelphone()) ? "" : vehicleDetail.getTelphone());
                    Glide.with(this).load(vehicleDetail.getImg()).apply(optionsCompany).into(binding.companyHeadImg);
                    binding.carCompanyName.setText(vehicleDetail.getRoleName());
                    binding.connectDriverName.setText(TextUtils.isEmpty(vehicleDetail.getName()) ? "/" : vehicleDetail.getName());
                    binding.ivShowCarCompanyDetail.setOnClickListener(view -> {
                        WebsiteInfoActivity.start(this, vehicleDetail.getCompanyNo(), WebsiteInfoActivity.WEBSITE_FOR_COMPANY);
                    });
                    binding.phone.setOnClickListener(view -> {
                        if (TextUtils.isEmpty(vehicleDetail.getTelphone()))
                            return;
                        new RoundDialog.Builder(getActivity())
                                .title("确认呼叫")
                                .content(vehicleDetail.getTelphone())
                                .confirm("确定")
                                .cancelable(false)
                                .confirmCallback(v -> {
                                    Intent intent = new Intent(Intent.ACTION_DIAL);
                                    Uri data = Uri.parse("tel:" + vehicleDetail.getTelphone());
                                    intent.setData(data);
                                    getActivity().startActivity(intent);
                                })
                                .show();
                    });
                    binding.oftenDeliverCity.setVisibility(View.GONE);
                } else if (vehicleDetail.getTerminal() == 2) {
                    binding.clCompanyCarOwner.setVisibility(View.VISIBLE);
                    binding.clDriverLayout.setVisibility(View.GONE);
                    binding.llInfo.setVisibility(View.GONE);
                    binding.tvInfoTip.setText("隶属团队");
                    binding.phone.setText(TextUtils.isEmpty(vehicleDetail.getTelphone()) ? "" : vehicleDetail.getTelphone());
                    Glide.with(this).load(vehicleDetail.getImg()).apply(optionsTeam).into(binding.companyHeadImg);
                    binding.carCompanyName.setText(vehicleDetail.getRoleName());
                    binding.connectDriverName.setText(TextUtils.isEmpty(vehicleDetail.getName()) ? "/" : vehicleDetail.getName());
                    binding.ivShowCarCompanyDetail.setOnClickListener(view -> {
                        WebsiteInfoActivity.start(this, vehicleDetail.getTeamNo(), WebsiteInfoActivity.WEBSITE_FOR_TEAM);
                    });
                    binding.phone.setOnClickListener(view -> {
                        if (TextUtils.isEmpty(vehicleDetail.getTelphone()))
                            return;
                        new RoundDialog.Builder(getActivity())
                                .title("确认呼叫")
                                .content(vehicleDetail.getTelphone())
                                .confirm("确定")
                                .cancelable(false)
                                .confirmCallback(v -> {
                                    Intent intent = new Intent(Intent.ACTION_DIAL);
                                    Uri data = Uri.parse("tel:" + vehicleDetail.getTelphone());
                                    intent.setData(data);
                                    getActivity().startActivity(intent);
                                })
                                .show();
                    });
                    binding.oftenDeliverCity.setVisibility(View.GONE);
                } else {
                    binding.clCompanyCarOwner.setVisibility(View.GONE);
                    binding.clDriverLayout.setVisibility(View.VISIBLE);
                    binding.llInfo.setVisibility(View.VISIBLE);
                    binding.tvInfoTip.setText("驾驶员信息");
                    binding.personPhone.setText(TextUtils.isEmpty(vehicleDetail.getTelphone()) ? "" : vehicleDetail.getTelphone());
                    if (vehicleDetail.getUserVO() != null) {
                        Glide.with(this).load(vehicleDetail.getUserVO().getHeadImg()).apply(optionsperson).into(binding.contactHeadImg);
                    }
                    binding.connectPersonName.setText(vehicleDetail.getRoleName());
                    binding.connectDriverNamePerson.setText(TextUtils.isEmpty(vehicleDetail.getName()) ? "/" : vehicleDetail.getName());
                    binding.clDriverLayout.setOnClickListener(view -> {
                        WebsiteInfoActivity.start(this, vehicleDetail.getUserNo(), WebsiteInfoActivity.WEBSITE_FOR_PERSONAL);
                    });
                    binding.personPhone.setOnClickListener(view -> {
                        if (TextUtils.isEmpty(vehicleDetail.getTelphone()))
                            return;
                        new RoundDialog.Builder(getActivity())
                                .title("确认呼叫")
                                .content(vehicleDetail.getTelphone())
                                .confirm("确定")
                                .cancelable(false)
                                .confirmCallback(v -> {
                                    Intent intent = new Intent(Intent.ACTION_DIAL);
                                    Uri data = Uri.parse("tel:" + vehicleDetail.getTelphone());
                                    intent.setData(data);
                                    getActivity().startActivity(intent);
                                })
                                .show();
                    });
                }
                if (vehicleDetail.getTerminal()!=3&&!TextUtils.isEmpty(vehicleDetail.getTheDriverName())){
                    binding.llCompanyTeamInfo.setVisibility(View.VISIBLE);
                    binding.ctDriverName.setText(TextUtils.isEmpty(vehicleDetail.getTheDriverName())?"/":vehicleDetail.getTheDriverName());
                    binding.ctDriverNation.setText(TextUtils.isEmpty(vehicleDetail.getNational())?"/":vehicleDetail.getNational());
                    binding.ctDriverNativePlace.setText(TextUtils.isEmpty(vehicleDetail.getNativePlace())?"/":vehicleDetail.getNativePlace());
                    binding.ctDriverAge.setText(TextUtils.isEmpty(vehicleDetail.getCarAge())?"/":vehicleDetail.getCarAge());
                    binding.ctDriverDriveTime.setText(TextUtils.isEmpty(vehicleDetail.getDriverAge())?"/":vehicleDetail.getDriverAge());
                }else {
                    binding.llCompanyTeamInfo.setVisibility(View.GONE);
                }
            }
        }


        if (!TextUtils.isEmpty(vehicleDetail.getNativePlace())) {
            binding.driverNativePlace.setText(vehicleDetail.getNativePlace());
        } else {
            binding.driverNativePlace.setText("/");
        }
        if (!TextUtils.isEmpty(vehicleDetail.getNational())) {
            binding.driverNation.setText(vehicleDetail.getNational());
        } else {
            binding.driverNation.setText("/");
        }
        if (!TextUtils.isEmpty(vehicleDetail.getCarAge())) {
            binding.driverAge.setText(vehicleDetail.getCarAge());
        } else {
            binding.driverAge.setText("/");
        }
        if (!TextUtils.isEmpty(vehicleDetail.getDriverAge())) {
            binding.driverDriveTime.setText(vehicleDetail.getDriverAge());
        } else {
            binding.driverDriveTime.setText("/");
        }
        if (!TextUtils.isEmpty(vehicleDetail.getIntentionProvinceName()) && !TextUtils.isEmpty(vehicleDetail.getIntentionCityName())) {
            binding.currentWhereToGo.setText(vehicleDetail.getIntentionProvinceName() + vehicleDetail.getIntentionCityName());
        } else {
            binding.currentWhereToGo.setText("/");
        }
        if (!TextUtils.isEmpty(vehicleDetail.getLinkman())) {
            binding.tvCarPrincipal.setText(vehicleDetail.getLinkman());
        } else {
            binding.tvCarPrincipal.setText("/");
        }
        if (!TextUtils.isEmpty(vehicleDetail.getLinkmanPhone())) {
            binding.tvPrincipalPhone.setText(vehicleDetail.getLinkmanPhone());
        } else {
            binding.tvPrincipalPhone.setText("/");
        }
    }

    private void setOftenCity() {
        if (vehicleDetail.getWay() == null || vehicleDetail.getWay().size() == 0) {
            binding.oftenDeliverCity.setVisibility(View.GONE);
            return;
        }

        Iterator<Way> iterator = vehicleDetail.getWay().iterator();
        while (iterator.hasNext()) {
            Way item = iterator.next();
            if (TextUtils.isEmpty(item.getCityName())) {
                iterator.remove();
            }
        }
        if (vehicleDetail.getWay().size() == 0 && (vehicleDetail.getFreight() == null || (vehicleDetail.getFreight()).intValue() == 0)) {
            binding.oftenDeliverCity.setVisibility(View.GONE);
            return;
        }

        binding.oftenDeliverCity.setVisibility(View.VISIBLE);
        binding.oftenDeliverCityRecycleview.setLayoutManager(new GridLayoutManager(this, 3));
        binding.oftenDeliverCityRecycleview.setAdapter(new OftenDeliverCityAdapter(this, vehicleDetail.getWay()));

        if ((vehicleDetail.getFreight() == null || vehicleDetail.getFreight() == 0)) {
            binding.intentionPriceLayout.setVisibility(View.GONE);
        } else {
            binding.intentionPriceLayout.setVisibility(View.VISIBLE);
            binding.intentionPrice.setText(vehicleDetail.getFreight() + vehicleDetail.getFreightUnitString());
        }
    }

    private void setCarrierVO() {
        if (vehicleDetail.getQueryTwoCarrierVO() == null || vehicleDetail.getQueryTwoCarrierVO().size() == 0) {
            binding.moreDeliverLayout.setVisibility(View.GONE);
            return;
        }
        binding.moreDeliverLayout.setVisibility(View.VISIBLE);
        if (vehicleDetail.getQueryTwoCarrierVO().size() > 2) {
            vehicleDetail.setQueryTwoCarrierVO(vehicleDetail.getQueryTwoCarrierVO().subList(0, 2));
        }
        for (QueryTwoCarrierVO item : vehicleDetail.getQueryTwoCarrierVO()) {
            binding.moreDeliverLayout.addView(new ItemDeliverView(this, item));
        }
    }

    private QualityMemberBean bean1;

    @Override
    public void onMultiClick(View v) {
        switch (v.getId()) {
            case R.id.enquiry:
                if (!isLogin()) {
                    VerificationCodeLoginActivity.start(VehicleDetailActivity.this);
                    return;
                }
                if (vehicleDetail != null && !UserOperating.getInstance().IsAuth(this, vehicleDetail.getAuthTime())) {
                    return;
                }
                model.refresh(this);

                break;
            case R.id.call_phone:
            case R.id.call_phone_company:
                if (!isLogin()) {
                    VerificationCodeLoginActivity.start(VehicleDetailActivity.this);
                    return;
                }
                if (vehicleDetail != null && !TextUtils.isEmpty(vehicleDetail.getTelphone())) {
                    new RoundDialog.Builder(getActivity())
                            .title("确认呼叫")
                            .content(vehicleDetail.getTelphone())
                            .confirm("拨打")
                            .cancelable(false)
                            .confirmCallback(view -> {
                                Intent intent = new Intent(Intent.ACTION_DIAL);
                                Uri data = Uri.parse("tel:" + vehicleDetail.getTelphone());
                                intent.setData(data);
                                getActivity().startActivity(intent);
                            })
                            .show();
                } else {
                    ToastUtil.show(this, "未获取到电话号码");
                }
                break;
            case R.id.tv_contact_service:
                if (!isLogin()) {
                    VerificationCodeLoginActivity.start(VehicleDetailActivity.this);
                    return;
                }
                if (vehicleDetail != null && !UserOperating.getInstance().IsAuth(this, vehicleDetail.getAuthTime())) {
                    return;
                }
                if (!contactsIsInSystem()) {
                    return;
                }
                if (vehicleDetail != null && !TextUtils.isEmpty(vehicleDetail.getUserVO().getImAccount())) {
                    buildSingleTalking(vehicleDetail.getUserVO().getImAccount());
                }

                break;
            case R.id.more_deliver_info:
                MoreCarriageInfoActivity.start(VehicleDetailActivity.this, vehicleDetail.getUserNo(), String.valueOf(vehicleDetail.getDriverAuthNo()));
                break;

            case R.id.ll_location_layout:
            case R.id.tv_map_operation:
            case R.id.tv_current_location:
                DriverLocationActivity.start(this, vehicleDetail);
                break;
            case R.id.ll_share_layout://分享
                if (vehicleDetail == null)
                    return;
                StringBuilder title = new StringBuilder();
                StringBuilder content = new StringBuilder();
                title.append(vehicleDetail.getCarNumber());

                if (!TextUtils.isEmpty(vehicleDetail.getCarTypeName())) {
                    content.append(vehicleDetail.getCarTypeName());
                }
                if (!TextUtils.isEmpty(vehicleDetail.getCarLenName())) {
                    content.append("/车长").append(vehicleDetail.getCarLenName());
                }
                if (vehicleDetail.getWeight() != null) {
                    content.append("/");
                    content.append(NumberUtil.trim0(vehicleDetail.getWeight()));
                    content.append("吨");
                }
                ShareLogisticsActivity.start(VehicleDetailActivity.this, title.toString(), content.toString(), vehicleDetail.getCarImage(), vehicleDetail.getShareUrl(), true);
                break;
            case R.id.inquiry:
                if (vehicleDetail != null && !UserOperating.getInstance().IsAuth(this, vehicleDetail.getAuthTime())) {
                    return;
                }
                if (!isLogin()) {
                    VerificationCodeLoginActivity.start(VehicleDetailActivity.this);
                    return;
                }
                InquireByLetterActvity.start(this, 2, vehicleDetail.getUserVO() != null && !TextUtils.isEmpty(vehicleDetail.getUserVO().getRealName()) ? vehicleDetail.getUserVO().getRealName() : "",
                        vehicleDetail.getUserNo(), String.valueOf(vehicleDetail.getDriverAuthNo()), vehicleDetail.getCarNumber());
                break;
            case R.id.report:
                if (!isLogin()) {
                    VerificationCodeLoginActivity.start(VehicleDetailActivity.this);
                    return;
                }
                if (vehicleDetail != null && !TextUtils.isEmpty(vehicleDetail.getTelphone())) {
                    new RoundDialog.Builder(getActivity())
                            .title("确认呼叫")
                            .content(vehicleDetail.getTelphone())
                            .confirm("拨打")
                            .cancelable(false)
                            .confirmCallback(view -> {
                                Intent intent = new Intent(Intent.ACTION_DIAL);
                                Uri data = Uri.parse("tel:" + vehicleDetail.getTelphone());
                                intent.setData(data);
                                getActivity().startActivity(intent);
                            })
                            .show();
                } else {
                    ToastUtil.show(this, "未获取到电话号码");
                }
                // ToastUtil.show(getActivity(), "功能正在开发中");
                break;
            case R.id.tv_invitation:
                if (vehicleDetail != null && !UserOperating.getInstance().IsAuth(this, vehicleDetail.getAuthTime())) {
                    return;
                }

                if (!MemberConfig.getInstance().isHavePermission("14_yaoqinghuiyuan1")) {//邀请会员权限
                    MToast.showToast(getActivity(), "没有权限操作，请找企业管理员分配权限");
                    return;
                }
                bean1 = new QualityMemberBean();
                bean1.setCompanyNo(vehicleDetail.getCompanyNo());
                bean1.setCompanyName(vehicleDetail.getName());
                bean1.setNo(vehicleDetail.getUserNo());

                if (MemberConfig.getInstance().getComType() == MemberConfig.WEBSITE_FOR_COMPANY) {
                    String companyNo = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.COMPANY_NO, "");
                    model.getProcessStatus(companyNo, "inviteJoinCompany");
                } else {
                    com.swgk.core.util.MToast.showToast(getActivity(), "个人/团队网站暂不支持该操作");
                }
                break;
        }
    }

    private void setImIconVisibilityAndClickListener() {
        if (vehicleDetail.getIsManage() || !contactsIsInSystem()) {
            binding.tvContactService.setOnClickListener(null);

        } else {
            binding.tvContactService.setOnClickListener(this);
        }
    }

    private boolean contactsIsInSystem() {
        if (vehicleDetail == null || vehicleDetail.getUserVO() == null ||
                TextUtils.isEmpty(vehicleDetail.getUserVO().getImAccount())) {
            return false;
        }
        return true;
    }


    private boolean isLogin() {
        return !"".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""));
    }

    public void setUserInfo() {
        if (UserOperating.getInstance().isNotOpenFundAccount(VehicleDetailActivity.this, PermissionCheckUtil.KEY_WODEXUNJIA)) {
            return;
        }
        model.getInquiryPermissions(String.valueOf(vehicleDetail.getDriverAuthNo()));
    }
}
